package com.chiang.apntest.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.util.Log;

public class PropertiesUtil {

	private static final String TAG = "PropertiesUtil";
	private Properties mProperties=null;
	
	private PropertiesUtil(){
		
	}
	
	public static PropertiesUtil readProperties(InputStream is){
		PropertiesUtil propertiesUtil=new PropertiesUtil();
		propertiesUtil.mProperties=new Properties();
		try {
			propertiesUtil.mProperties.load(is);
		} catch (IOException e) {
			Log.e(TAG, "-------read properties error,caused by:"+e.getMessage());
		}
		return propertiesUtil;
	}
	
	public String getString(String key, String def) {
		String value = mProperties.getProperty(key);
		return value == null ? def : value;
	}
	
	public Integer getInteger(String key, Integer def) {
		String value = mProperties.getProperty(key);
		return value == null ? def : Integer.valueOf(value);
	}
}

